#include<iostream>
#include<queue>
using namespace std;

int main(){
	int m,n;
	queue<int> q;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		q.push(i);
	}
	int cur=1;
	while(q.size()>1){
		int x=q.front();
		q.pop();
		if(cur==m){
			cur=1;
		}else{
			q.push(x);
			cur++;
		}
	}
	cout<<q.front();
	return 0;
} 
